﻿using BCCommon;
using BCCommon.TMS.FreightEnums;
using BCDto.TMS.HorsemanFreightExtention;
using BCService.TMS.HorsemanFreightExtention;
using BCTMSRESTful.Configs;
using BCTMSRESTful.Controllers.Management;
using Microsoft.AspNetCore.Mvc;
using System.Net;

namespace BCTMSRESTful.Controllers.Management.TMS.HorsemanFreightConfiguration
{
    /// <summary>
    /// 骑手运费阶梯
    /// </summary>
    [Route("api/v1/sim/[controller]")]
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    public class HorsemanFreightExtentionController : ManagementBaseController
    {
        private readonly IHorsemanFreightExtentionService horsemanFreightExtentionService;
        public HorsemanFreightExtentionController(IHorsemanFreightExtentionService horsemanFreightExtentionService)
        {
            this.horsemanFreightExtentionService = horsemanFreightExtentionService;
        }


        /// <summary>
        /// 创建骑手运费阶梯
        /// </summary>
        /// <param name="dto"></param>
        /// <response code="200">创建骑手运费阶梯成功。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <returns></returns>
        [HttpPost]
        [Log("创建骑手运费阶梯")]
        [ProducesResponseType(typeof(HorsemanFreightExtentionDto), 200)]
        public IActionResult Post([FromBody] HorsemanFreightExtentionRequestDto dto)
        {
            int result = this.horsemanFreightExtentionService.Add(this.Admin, dto);
            return StatusCode((int)HttpStatusCode.Created, result);
        }

        /// <summary>
        /// 获取指定的骑手运费阶梯
        /// </summary>
        /// <param name="horsemanFreightExtentionId">骑手运费阶梯Id</param>
        /// <response code="200">查询骑手运费阶梯成功。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <returns></returns>
        [HttpGet("{horseman_freight_extention_id}")]
        [ProducesResponseType(typeof(HorsemanFreightExtentionDto), 200)]
        public IActionResult Get([FromRoute(Name = "horseman_freight_extention_id")] long horsemanFreightExtentionId)
        {
            return Ok(this.horsemanFreightExtentionService.GetByHorsemanFreightExtentionIdId(horsemanFreightExtentionId));
        }

        /// <summary>
        /// 更新骑手运费阶梯信息
        /// </summary>
        /// <param name="horsemanFreightExtentionId">骑手运费阶梯Id</param>
        /// <param name="dto">骑手运费阶梯修改内容</param>
        /// <response code="200">更新骑手运费阶梯成功。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <returns></returns>
        [HttpPut("{horseman_freight_extention_id}")]
        [Log("更新骑手运费阶梯信息")]
        [ProducesResponseType(typeof(HorsemanFreightExtentionDto), 200)]
        public IActionResult Put([FromRoute(Name = "horseman_freight_extention_id")] int horsemanFreightExtentionId, [FromBody] HorsemanFreightExtentionPutDto dto)
        {
            return this.Ok(this.horsemanFreightExtentionService.Update(horsemanFreightExtentionId, dto));
        }
        /// <summary>
        /// 批量更新骑手运费阶梯信息
        /// </summary>
        /// <param name="countyCode">区县编码</param>
        /// <param name="dto">骑手运费阶梯修改内容</param>
        /// <response code="200">更新骑手运费阶梯成功。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <returns></returns>
        [HttpPost("[action]/{county_code}")]
        [Log("批量更新骑手运费阶梯信息")]
        [ProducesResponseType(typeof(bool), 200)]
        public IActionResult BatchUpdate([FromRoute(Name = "county_code")] string countyCode, [FromBody] HorsemanFreightExtentionBatchPutDto dto)
        {
            return this.Ok(this.horsemanFreightExtentionService.BatchUpdate(this.Admin, countyCode, dto));
        }
        /// <summary>
        /// 获取骑手运费阶梯（分页）
        /// </summary> 
        /// <param name="isBase">是否是基础骑手运费阶梯</param>     
        /// <param name="countyCode">区县编码</param>
        /// <param name="freightExtentionType">阶梯运费类型</param>
        /// <param name="ascending">是否升序排序</param>
        /// <param name="sortName">排序字段</param>
        /// <param name="index">当前页</param>
        /// <param name="size">每页条数</param>
        /// <response code="200">获取骑手运费阶梯列表成功。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        [HttpGet]
        [ProducesResponseType(typeof(PageableList<HorsemanFreightExtentionViewDto>), 200)]
        public IActionResult Get(
            [FromQuery(Name = "is_base")] bool? isBase,
            [FromQuery(Name = "county_code")] string countyCode,
            [FromQuery(Name = "freight_extention_type")] HorsemanFreightExtentionType? freightExtentionType,
            [FromQuery(Name = "ascending")] bool? ascending,
            [FromQuery(Name = "sort_name")] string sortName,
            [FromQuery(Name = "index")] int index = 1,
            [FromQuery(Name = "size")] int size = 10)
        {
            var list = this.horsemanFreightExtentionService.GetList(this.Admin, isBase, countyCode, freightExtentionType, ascending, sortName, index, size);
            return this.Ok(list);
        }
    }
}
